#include "ipmsguser.h"

/**
 * @brief 用户信息的构造函数
 * @param parent
 */
IpMsgUser::IpMsgUser(QObject *parent) : QObject(parent)
{
    // 清空成员变量的内容
    userVer  .clear();
    userId   .clear();
    userIcon .clear();
    userEmail.clear();
    userHostAddr.clear();
    userHostName.clear();
    userNickName.clear();
    userGroupName.clear();
    userPktSeq = 0;
    userCfmSeq = 0;

    // 构造新的聊天界面
    chatForm   = new FormChat();
}

IpMsgUser::~IpMsgUser()
{
    qout << "Do nothing for" << this->userId;
//    dumpUserInfo();
}


/**
 * @brief 输出用户信息
 */
void IpMsgUser::dumpUserInfo()
{
    qout << "IpAddr:"     << userHostAddr.toString();
    qout << "Version:"    << QString(userVer);
    qout << "UserId:"     << QString(QTextCodec::codecForName ("gbk")->toUnicode (userId)      )  ;
    qout << "NickName:"   << QString(QTextCodec::codecForName ("gbk")->toUnicode (userNickName))  ;
    qout << "Group:"      << QString(userGroupName)  ;
    qout << "Hostname:"   << QString(QTextCodec::codecForName ("gbk")->toUnicode (userHostName))  ;
    qout << "PacketSeq:"  << userPktSeq     ;
    return;
}

/**
 * @brief 增加聊天记录数据
 * @param data 需要增加的字符串
 */
void IpMsgUser::appendChatHistory(QString data)
{
    chatHistory.append(data);
    return;
}

/**
 * @brief 聊天界面更新聊天记录
 */
void IpMsgUser::updateChatFormHistory()
{
    if(chatForm != nullptr)
    {
//        chatForm->updateChatHistory(chatHistory.toUtf8());
        chatForm->updateChatHistory(chatHistory);
    }
}
